<!-- shopList页面 -->
<template>
	<view>
		<!-- 顶部栏 -->
		<view class="header-section">
			<view class="flex justify-between align-center"><text style="color: black;">服务</text></view>
			<view class="flex justify-between align-center">
				<!-- <input type="text" class="search-input" placeholder="这里放搜索框" />
				<uni-icons type="search" size="30" class="search-icon"></uni-icons> -->
			</view>
		</view>
		<!-- 分类选择 -->
		<view class="categories">
			<view class="category-item" :class="{ 'active-category': selectedTag === tag }" v-for="tag in tags"
				:key="tag" @click="selectTag(tag)">
				{{ tag }}
			</view>
		</view>
		<!-- 地址-->
		<view class="map " @click="tomap">
			<view>地址
				<img style="height: 20px;width: 20px;" src="/static/images/map.png">
			</view>
		</view>

		<!-- 商店列表 -->
		<scroll-view class="store-list" scroll-y>
			<view class="store-item" v-for="shop in shopList" :key="shop.storeId">
				<uni-row>
					<uni-card>
						<uni-col :span="8">
							<img v-if="shop.storeLogo" :src="baseUrl+shop.storeLogo" class="store-image"
								mode="scaleToFill" @click="shopdetail(shop.storeId)">
							</img>
						</uni-col>
						<uni-col :span="10">
							<view class="store-mid">
								<view v-if="shop.storeName" class="store-description">店名:{{ shop.storeName }}</view>
								<view v-if="shop.storeAddress" class="store-description">地址:{{ shop.storeAddress }}
								</view>
								<view v-if="shop.storeOpen" class="store-description">营业时间:{{ shop.storeOpen}}-</view>
								<view v-if="shop.storeClose" class="store-description">{{ shop.storeClose}}</view>
							</view>
						</uni-col>
						<uni-col :span="6">
							<view class="store-mid">
								<view> 评分
									<img style="height: 20px;width: 20px;" src="/static/images/score.png">
								</view>
								<view> 导航
									<img style="height: 20px;width: 20px;" src="/static/images/navigation.png">
								</view>
							</view>
						</uni-col>
					</uni-card>
				</uni-row>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		getAllShop,
		getShopByTag,
		getShopById
	} from '../../api/shop'
	import config from '@/config'
	const baseUrl = config.baseUrl
	export default {
		data() {
			return {
				tags: ["配对", "清洁", "医疗", "疫苗", "体验"],
				selectedTag: '',
				shopList: [],
				baseUrl: '',
			}
		},
		created() {
			getAllShop().then(res => {
				this.shopList = res.data;
				this.baseUrl = baseUrl;
			})
		},
		methods: {
			selectTag(tag) {
				this.selectedTag = tag;
				this.fetchShopList(tag);
			},
			fetchShopList(tag) {
				getShopByTag(tag).then(response => {
					if (response.code === 200) {
						this.shopList = response.data;
						console.log(response)
					}
				}).catch(error => {
					console.error(error);
				});
			},
			shopdetail(storeId) {
				this.$tab.redirectTo(`/pages/service/shopDetail?storeId=${storeId}`)
			},
			tomap() {
				this.$tab.redirectTo(`/pages/service/service`)
			},
		}
	}
</script>

<style>
	.categories {
		display: flex;
		justify-content: space-around;
		padding: 10px;
		background-color: #fff;
	}

	.map {
		display: flex;
		justify-content: space-around;
		padding: 10px;
		background-color: #fff;
	}

	.category-item {
		padding: 10px;
		font-size: 16px;
		color: #333;
		cursor: pointer;
	}

	.category-item.active-category {
		color: white;
		background-color: #3c96f3;
		border-radius: 5px;
	}

	.header-section {
		padding: 15px;
		background-color: #ffcbb2;
		color: white;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.categories {
		display: flex;
		justify-content: space-around;
		padding: 10px;
		background-color: #fff;
		margin-right: 10px;
		overflow: hidden;
	}

	.store-list {
		padding: 10px;
	}

	.store-item {
		display: flex;
		flex-direction: column;
		background-color: #fff;
		margin-bottom: 10px;
		padding: 10px;
		border-radius: 5px;
	}

	.store-image {
		width: 100px;
		height: 100px;
		margin-top: 10px;
		display: flex;
		border-radius: 5px;
		object-fit: scaleToFill;

	}

	.store-mid {
		word-wrap: break-word;
		height: 100px;
	}

	.store-right {
		word-wrap: break-word;
		height: 100px;
		display: flex;
		flex-direction: column;
		justify-content: center;
	}

	.store-description {
		margin-bottom: 5px;
		font-size: 14px;
		color: #333;
		text-align: center;
	}
</style>